Skip to content

feat: use runtime Gradle version during plugin AAR build #3731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 10, 2018

Conversation

DimitarTachev
Copy link
Contributor

PR Checklist

Related to #3719

for (const dir of androidSourceSetDirectories) {
const dirNameParts = dir.split(path.sep);
// get only the last subdirectory of the entire path string. e.g. 'res', 'java', etc.
const dirName = dirNameParts[dirNameParts.length - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use path.dirname(path.dirname(dir))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after a further looking into that, it could be just path.basename(dir)

const includeGradleContent = this.$fs.readText(includeGradlePath);
const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent);
private replaceGradleVersion(pluginTempDir: string, version: string): void {
const gradleVersion = version || "4.4";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4.4 can be extracted to constant

}
private replaceGradleAndroidPluginVersion(buildGradlePath: string, version: string): void {
const gradleAndroidPluginVersionPlaceholder = "{{runtimeAndroidPluginVersion}}";
const gradleAndroidPluginVersion = version || "3.1.2";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can be extracted to constant - 3.1.2

const includeGradlePath = path.join(platformsAndroidDirPath, INCLUDE_GRADLE_NAME);
if (this.$fs.exists(includeGradlePath)) {
const includeGradleContent = this.$fs.readText(includeGradlePath);
const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe compileDependencies is a better name. It is not a good practice to have and in the name.

androidManifestContent = this.$fs.readText(manifestFilePath);
} catch (err) {
throw new Error(
`Failed to fs.readFileSync the manifest file located at ${manifestFilePath}`
Copy link
Contributor

@Fatme Fatme Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be nice to add the message from real error here.

`Failed to fs.readFileSync the manifest file located at ${manifestFilePath}`

Also use $errors.failWithoutHelp

try {
this.$fs.writeFile(pathToTempAndroidManifest, updatedManifestContent);
} catch (e) {
throw new Error(`Failed to write the updated AndroidManifest in the new location - ${pathToTempAndroidManifest}`);
Copy link
Contributor

@Fatme Fatme Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we can add the real error message to the output.
Use this.$errors.fail

const packageJsonGradle = packageData && packageData.gradle;
let runtimeVersions: IRuntimeGradleVersions = null;
if (packageJsonGradle && (packageJsonGradle.version || packageJsonGradle.android)) {
runtimeVersions = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this line and initialize the variable when declaring it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its here as we want to return null in such cases

const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent);

if (repositoriesAndDependenciesScopes.length > 0) {
this.$fs.appendFile(buildGradlePath, "\n" + repositoriesAndDependenciesScopes.join("\n"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe EOL is better than \n

this.$fs.copyFile(pathToBuiltAar, path.join(aarOutputDir, `${shortPluginName}.aar`));
}
} catch (e) {
throw new Error(`Failed to copy built aar to destination. ${e.message}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add the real error message to the output.

@Natalia-Hristova Natalia-Hristova added this to the 4.2.0 milestone Jul 6, 2018
@@ -123,7 +123,7 @@ export class NodePackageManager implements INodePackageManager {
const url = `https://registry.npmjs.org/${packageName}`;
this.$logger.trace(`Trying to get data from npm registry for package ${packageName}, url is: ${url}`);
const responseData = (await this.$httpClient.httpRequest(url)).body;
this.$logger.trace(`Successfully received data from npm registry for package ${packageName}. Response data is: ${responseData}`);
this.$logger.trace(`Successfully received data from npm registry for package ${packageName}.`);
const jsonData = JSON.parse(responseData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you delete response data from the log message? It is added here with debug purposes?

@@ -164,113 +169,157 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
*/
public async buildAar(options: IBuildOptions): Promise<boolean> {
this.validateOptions(options);
const manifestFilePath = this.getManifest(options.platformsAndroidDirPath);
const androidSourceSetDirectories = this.getAndroidSourceDirectories(options.platformsAndroidDirPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe androidSourceDirectories is a better name.

androidManifestContent = this.$fs.readText(manifestFilePath);
} catch (err) {
throw new Error(
`Failed to fs.readFileSync the manifest file located at ${manifestFilePath}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this.$errors.fail or this.$erros.failWithoutHelp instead throw new Error

const includeGradleContent = this.$fs.readText(includeGradlePath);
const repositoriesAndDependenciesScopes = this.getIncludeGradleCompileDependenciesScope(includeGradleContent);

if (repositoriesAndDependenciesScopes.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repositoriesAndDependenciesScopes.length is enough

throw new Error(`Failed to copy built aar to destination. ${e.message}`);
}
} else {
throw new Error(`No built aar found at ${pathToBuiltAar}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.fail()

};
}

function setupDI(options: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe createTestInjector is a better name

@dtopuzov
Copy link
Contributor

dtopuzov commented Jul 9, 2018

run ci

2 similar comments
@Natalia-Hristova
Copy link

run ci

@Natalia-Hristova
Copy link

run ci

Copy link
Contributor

@rosen-vladimirov rosen-vladimirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really great work!

@@ -33,5 +34,5 @@ interface IBuildAndroidPluginData {
/**
* Information about tools that will be used to build the plugin, for example compile SDK version, build tools version, etc.
*/
androidToolsInfo: IAndroidToolsInfoData;
androidToolsInfo?: IAndroidToolsInfoData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is not mandatory anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using it in a single place and now it defaults to the old logic inside (this.$androidToolsInfo.getToolsInfo();)

@Natalia-Hristova
Copy link

run ci

Copy link
Contributor

@Fatme Fatme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!!

@DimitarTachev DimitarTachev force-pushed the tachev/use-runtime-gradle-version branch 3 times, most recently from ad8fe7f to 4f46b6a Compare July 10, 2018 11:33
@DimitarTachev DimitarTachev force-pushed the tachev/use-runtime-gradle-version branch from 4f46b6a to 1a881a1 Compare July 10, 2018 11:53
@DimitarTachev DimitarTachev merged commit 42e4210 into master Jul 10, 2018
@DimitarTachev DimitarTachev deleted the tachev/use-runtime-gradle-version branch July 10, 2018 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants